<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>剩余参数</title>
</head>
<body>
  <script>
    /**
     * 1. 数组剩余参数
     * 2.对象剩余参数
    */
   
    // 1. 数组剩余参数
    const arr = [1, 2, 3];
    const [one, ...two] = arr;
    console.log('arrRest', one, two);

    // 2. 对象剩余参数
    const obj = {a: 1, b: 2, c: 3};
    const { a: objA, ...objTwo } = obj;
    console.log('objRest', objA, objTwo);

    // 真实应用（求和）
    function sum (...params) {
      console.log('params', params);
      return params.reduce((prev, curr) => prev + curr, 0);
    }
    const sumRest = sum(1, 2, 3);
    console.log('sumRest', sumRest);
  </script>
</body>
</html> 